//
//  UIView+WJCBaseXibDeploy.m
//  花絮
//
//  Created by wjc on 2021/11/14.
//  Copyright © 2021 飞麦科技. All rights reserved.
//

#import "UIView+WJCBaseXibDeploy.h"
#import <objc/runtime.h>
@implementation UIView (WJCBaseXibDeploy)
-(void)setModelDeploy:(NSString *)modelDeploy{
    objc_setAssociatedObject(self, @selector(modelDeploy), modelDeploy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)modelDeploy{
    return objc_getAssociatedObject(self, @selector(modelDeploy));
}
-(void)setTagStr:(NSString *)tagStr{
    objc_setAssociatedObject(self, @selector(tagStr), tagStr, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)tagStr{
    return objc_getAssociatedObject(self, @selector(tagStr));
}
-(void)setHeadDeploy:(NSString *)headDeploy{
    objc_setAssociatedObject(self, @selector(headDeploy), headDeploy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)headDeploy{
    return objc_getAssociatedObject(self, @selector(headDeploy));
}
-(void)setFootDeploy:(NSString *)footDeploy{
    objc_setAssociatedObject(self, @selector(footDeploy), footDeploy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)footDeploy{
    return objc_getAssociatedObject(self, @selector(footDeploy));
}
-(void)setBtnDeploykey:(NSString *)btnDeploykey{
    objc_setAssociatedObject(self, @selector(btnDeploykey), btnDeploykey, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)btnDeploykey{
    return objc_getAssociatedObject(self, @selector(btnDeploykey));
}

-(UIView *)getInnerWithTagStr:(NSString *)tagStr{
    for (UIView *v in self.subviews) {
        if ([v.tagStr isEqual:tagStr]) {
            return v;
        }else{
            if (v.subviews.count>0) {
                UIView *view = [v getInnerWithTagStr:tagStr];
                if (view) {
                    return view;
                }
            }
        }
    }
    return nil;
}
-(NSLayoutConstraint *)getInnerViewConstrantWithTagStr:(NSString *)tagStr andConstantStr:(NSString *)constraintRagStr{
    UIView *view = [self getInnerWithTagStr:tagStr];
    if (view) {
        NSArray *verticalConstraints =self.constraints;
        for (NSLayoutConstraint *layout in verticalConstraints) {
            if ([layout.constraintRagStr isEqual:constraintRagStr]) {
                return layout;
            }
        }
    }
    return nil;
}
-(NSArray<UIView *> *)getInnerViewsWithTagStr:(NSString *)tagStr{
    NSMutableArray *arr = [NSMutableArray new];
    for (UIView *v in self.subviews) {
        if ([v.tagStr isEqual:tagStr]) {
            [arr addObject:v];
        }
        if (v.subviews.count>0) {
                NSArray *viewArr = [v getInnerViewsWithTagStr:tagStr];
                if (viewArr.count>0) {
                    [arr addObjectsFromArray:viewArr];
                }
            }
        }
    return arr;
}
-(NSArray<UIView *> *)getInnerViewsWithClass:(Class)cls{
    NSMutableArray *arr = [NSMutableArray new];
    for (UIView *v in self.subviews) {
        if ([v.tagStr isKindOfClass:cls]) {
            [arr addObject:v];
        }
        if (v.subviews.count>0) {
                NSArray *viewArr = [v getInnerViewsWithClass:cls];
                if (viewArr.count>0) {
                    [arr addObjectsFromArray:viewArr];
                }
            }
        }
    return arr;
}
-(NSLayoutConstraint *)getConstantStr:(NSString *)constraintRagStr{
    NSArray *verticalConstraints =self.constraints;
    for (NSLayoutConstraint *layout in verticalConstraints) {
        if ([layout.constraintRagStr isEqual:constraintRagStr]) {
            return layout;
        }
    }
    if (self.subviews.count>0) {
        for (UIView *v in self.subviews) {
            return [v getConstantStr:constraintRagStr];
        }
    }
    return nil;
}
@end
